package com.kunbo.cn.app.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.aliyuncs.exceptions.ClientException;
import com.kunbo.cn.app.util.Verificationcode;
import com.kunbo.cn.util.common.Const;
import com.kunbo.cn.util.retu.BuildBean;
import com.kunbo.cn.util.retu.ResultBean;

/** 
 * 系统短信通知
* @ClassName:：SystemSMSAdjustmentController 
* @Description： TODO
* @author ： Mr.liu
* @date ：2019年4月3日 上午11:12:48 
*  
*/
@RestController
@RequestMapping("/system/send")
public class SystemSMSAdjustmentController {
	
	@Autowired
	private JdbcTemplate jdbc;
	
	
	@PostMapping("/sms")
	public ResultBean<Boolean> sms(
			@RequestParam("phone")String phone,
			@RequestParam("name")String name,
			@RequestParam("company")String company,
			@RequestParam("orderCode")String orderCode
			) throws ClientException{
		ResultBean<Boolean> result = new ResultBean<Boolean>();
		String sql = "SELECT contact_number FROM transport_unit_management where name_of_transport_unit = '"+company+"'";
		List<Map<String,Object>> map = jdbc.queryForList(sql);
		if(map.size()>0) {
		return BuildBean.buildResult(result, Const.success, Const.error, Verificationcode.dispatchingCarsSendMsg(phone, name,company,map.get(0).get("contact_number").toString(),orderCode));
		}else{
			return BuildBean.buildResult(result, Const.success, Const.error, Verificationcode.dispatchingCarsSendMsg(phone, name,company,"",orderCode));
		}
		}
	
}
